//
//  ZCSamplingDetailVC.m
//  zctx
//
//  Created by apple on 15/10/12.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCSamplingDetailVC.h"
#import "ZCSamplingProgressCell.h"
@interface ZCSamplingDetailVC ()

@end

@implementation ZCSamplingDetailVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 418+50);
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH,self.tableView.bounds.size.height);//头部
    [self.collectionView setCollectionViewLayout:flowLayout];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCSamplingProgressCell" bundle:nil] forCellReuseIdentifier:@"samplingdetail"];
}

#pragma mark 请求支持者数据
-(void)requestSupporterdata{
    ProgressHUDStr;
    [NetworkManager requestFoundingGetOneSponsorWithId:self.pid Mid:UserModel.mid password:UserModel.password pagecount:@"0" success:^(NSDictionary *dictResponse) {
        ProgressDismiss;
        sponsorArray = [[dictResponse objectForKey:@"content"] mutableCopy];
        [self.collectionView reloadData];
        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
    
    } failure:^(NSError *error) {
        ProgressDismiss;
    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZCProjectdetailsModel *detailsmodel = [ZCProjectdetailsModel modelObjectWithDictionary:datadictionary];
    
    if (indexPath.section==0) {
        ZCprojectdetailinfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"info"];
        cell.detailesModel = detailsmodel;
        return cell;
    }else if (indexPath.section==1){
        ZCSamplingProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"samplingdetail"];
        cell.nameLable.text = [NSString stringWithFormat:@"%@抽样检测中",detailsmodel.institution];
        return cell;
    }else if(indexPath.section==2){
        ZCProjectdetailallinfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"allinfo"];
        NSInteger money = [[NSString stringWithFormat:@"%@",detailsmodel.emoney]integerValue]/100;
        cell.emoneyLable.text = [NSString stringWithFormat:@"￥%ld 已筹齐",money];
        cell.countLable.text = [NSString stringWithFormat:@"%lu人已支持",(unsigned long)sponsorArray.count];
        return cell;
    }else{
        ZCProjectdetailSamplingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sampling"];
        [cell.contentView removeFromSuperview];
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 148;
    }else if (indexPath.section==1){
        return 60;
    }else if(indexPath.section==2){
        return 50;
    }else{
        return 10;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  
    NSArray *titleArray = [NSArray arrayWithObjects:@"基本信息",@"项目进度",@"众筹信息",@"支持者",nil];
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    headView.backgroundColor = [UIColor whiteColor];
    UIView *bgheadView = [UIView new];
    [headView addSubview:bgheadView];
    bgheadView.backgroundColor = [UIColor colorWithHexString:@"#ebeded"];
    [bgheadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.top).with.offset(0);
        make.left.equalTo(headView).with.offset(0);
        make.right.equalTo(headView).with.offset(0);
        make.height.mas_equalTo(@10);
    }];
    
    UIView *newView = [UIView new];
    [headView addSubview:newView];
    [newView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.top).with.offset(10);
        make.left.equalTo(headView).with.offset(0);
        make.right.equalTo(headView).with.offset(0);
        make.bottom.equalTo(headView).with.offset(0);
    }];
    
    UILabel *leftlable = [UILabel new];
    [newView addSubview:leftlable];
    leftlable.font = [UIFont systemFontOfSize:16];
    [leftlable setText:titleArray[section]];
    //        [leftlable setText:@"最新检测结果"];
    [leftlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(newView.mas_centerY);
        make.left.equalTo(newView).with.offset(15);
        make.height.mas_equalTo(@30);
        make.width.mas_equalTo(@150);
    }];
    
    if (section==1) {
        UILabel *statelable = [UILabel new];
        [newView addSubview:statelable];
        statelable.font = [UIFont systemFontOfSize:16];
        statelable.textColor = CellTextColor;
        [statelable setText:@"筹资完成,抽样中"];
        [statelable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(newView.mas_centerY);
            make.right.equalTo(newView).with.offset(-15);
            make.height.mas_equalTo(@30);
        }];

    }
    return headView;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
